import tensorflow as tf
import numpy as np
import pandas as pd
import autoencoder_train
import network
import utils
datadir = "/home/cjw/disk2cjw/Data/cyto/"
#datadir = "/home/cjw/disk2cjw/Data/yeast/"
mmfilename = datadir + "Fish6_15_cjw_mean_zero.mm"
#mmfilename = datadir + "mmplate15-1.mm"
mmheader = np.memmap(mmfilename, dtype="int32", mode='r',
shape=(4,))
header_shape = mmheader.shape
print(header_shape, mmheader)
xshape = [mmheader[0], mmheader[1], mmheader[2], mmheader[3]]
#xshape[0] = 2400
xshape = tuple(xshape)
del mmheader
print(xshape)
m3 = np.memmap(mmfilename, dtype='float32', offset=128,
mode='r', shape=xshape)
n = xshape[0]
ids = range(n)
file = n*['Fish6_15_cjw_64.tif']
fid = range(n)
mmfile = n*['Fish6_15_cjw_64.tif.mm']
plate = n*[0]
row = n*[0]
column = n*[0]
field = n*[0]
yc = n*[32]
xc = n*[32]
well = n*[0]
p_df = pd.DataFrame({'id':ids, 'fid':fid, 'file':file, 'mmfile':mmfile, 'plate':plate,
'row':row, 'column':column, 'field':field,
'yc':yc, 'xc':xc, 'well':well})
p_df.head()
p_mmdict = {"Fish6_15_cjw_64.tif.mm": m3}
# "plate04_all.mm": m4}
p_width = 64
p_height = 64
p_nchannels = 1
p_channels = [0]
p_nepochs = 60
p_batchsize = 32
p_learning_rate = 0.00005 #.00005
p_restore = False
p_latent_size = 128
# enc_sizes = [(8, 7), (16, 5), (32, 3), (64, 3)]
enc_sizes = [(64, 5), (128, 3), (256,3), (512,3)] #, (64, 3), (128,3)] #, (32, 3), (64, 3)]
#enc_sizes = [(16, 5), (32, 3), (64,3), (128,3)] #, (64, 3), (128,3)] #, (32, 3), (64, 3)]
dec_sizes = list(reversed(enc_sizes))
#dec_sizes.append((p_nchannels,7))
params = dict()
params['width'] = p_width
params['height'] = p_height
params['nchannels'] = p_nchannels
params['channels'] = p_channels
params['nepochs'] = p_nepochs
params['batchsize'] = p_batchsize
params['learning_rate'] = p_learning_rate
params['restore'] = p_restore
params['latent_size'] = p_latent_size
params['droprate'] = 0.75
params['enc_sizes'] = enc_sizes
params['dec_sizes'] = dec_sizes
autoencoder_train.train(p_mmdict, p_df, params, 100)